package com.gxa.service.discrepancy.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.discrepancy.Passage;
import com.gxa.entity.discrepancy.search.PassageSearchMap;
import com.gxa.mapper.discrepancy.PassageMapper;
import com.gxa.service.discrepancy.PassageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Service
public class PassageServiceImpl extends ServiceImpl<PassageMapper, Passage> implements PassageService {

    @Autowired
    private PassageMapper mapper;
    @Override
    public PageInfo<Passage> queryByPage(PassageSearchMap map) {
        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<Passage> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (!StringUtils.isAnyBlank(map.getName())) {
            wrapper.like("user_name", map.getName());
        }

        if(map.getType() != null && map.getType() != 0){
            wrapper.like("owner_type",map.getType());
        }
        if (!StringUtils.isAnyBlank(map.getPassLocation())) {
            wrapper.like("passage_places", map.getPassLocation());
        }
        if(!StringUtils.isAnyBlank(map.getStartTime(),map.getEndTime())){
            wrapper.between("records_time",map.getStartTime(),map.getEndTime());
        }
        PageInfo<Passage> pageInfo = new PageInfo<>(mapper.selectByPage(wrapper));//3.获取分页信息
        return pageInfo;
    }

    @Override
    public Set<String> getPassLocations() {
        return mapper.getPassLocations();
    }
}
